package com.woniu.maintain.controller;

import com.woniu.common.entity.JpMaintain;
import com.woniu.common.utils.ResultVO;
import com.woniu.maintain.service.JpMaintionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author 啊川
 * @version 1.0
 * @date 2021/9/16 19:18
 * @QQ 836782490
 * @content:
 */
@RestController
@RequestMapping("JpMaintion")
public class JpMaintainController {
    @Autowired
    private JpMaintionService jpMaintionService;

    @GetMapping("findAll")
    public ResultVO findAll() {
        try {
            List<JpMaintain> jpMaintainList = jpMaintionService.findAll();
            System.out.println(jpMaintainList);
            if ( jpMaintainList.size()!=0){
              return ResultVO.success("维修记录查询成功",jpMaintainList);
            }else {
              return ResultVO.fail("维修记录查询失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.fail("维修记录查询异常");
        }
    }


    @GetMapping("findById1/{id}")
    public ResultVO<JpMaintain> findById(@PathVariable("id") Integer id) {
        try {
            JpMaintain jpMaintain = jpMaintionService.findById(id);
            System.out.println(jpMaintain);
            if (jpMaintain == null) {
                return ResultVO.fail("维修记录查询失败");
            } else {
                return ResultVO.success("维修记录查询成功", jpMaintain);
            }
        } catch (Exception e) {
            return ResultVO.fail("维修记录查询异常");
        }
    }

}
